package DBman;

import java.util.ArrayList;
import scheduler.AuthenticationPair;
import scheduler.IdentifierPair;


/**
 * This class is used to create user objects. It contains the user's 
 * APS site ID, their encrypted password, generic user data and a list of 
 * scrape jobs corresponding to the billing sites the user is registered for.
 * @author Johann Jungbauer
 */
public class User {
  
    private String _UserID;
    private String _SitePW;
    private String _Name;
    private ArrayList<JobData> _Jobs = new ArrayList<JobData>();

    public User(String id, String pw, String name)
    {
        setUserID(id);
        setName(name);
        setSitePW(pw);
    }
    
    public void addJob(JobData job)
    {
        //System.out.println("$$ "+job.getBillingSiteRef());
        JobData add = job;
        _Jobs.add(add);
    }
    
    public void addJobs(ArrayList<JobData> jobs)
    {
        _Jobs = jobs;
    }
    
    public void removeJob(String billingRef)
    {
        int pos = 0;

        while(pos < _Jobs.size())
        {
            if(_Jobs.get(pos).getBillingSiteRef().compareTo(billingRef) == 0)
            {
                _Jobs.remove(pos);
            }
            pos++;
        }

    }
    
    public ArrayList<JobData> getJobs()
    {
        return _Jobs;
    }
    
    public void setSitePW(String pw)
    {
        _SitePW = pw;
    }
    
    public void setName(String name)
    {
        _Name = name;
    }
    
    public void setUserID(String id)
    {
        _UserID = id;
    }
    
    public String getSitePW()
    {
        return _SitePW;
    }
    
    public String getName()
    {
        return _Name;
    }
    
    public String getUserID()
    {
        return _UserID;
    }
    
    /**
     * Used to print the data in the object to System.out.
     * @param
     */
    public void printUser()
    {
        System.out.println(_UserID);
        System.out.println(_SitePW);
        System.out.println(_Name);
        
        System.out.println(_Jobs.size());
        
        for(int i = 0; i < _Jobs.size(); i++)
        {
            System.out.println(_Jobs.get(i).getBillingSiteRef());
            System.out.println(_Jobs.get(i).getStatus());
            System.out.println(_Jobs.get(i).getLatestResult());
            
            AuthenticationPair atemp[] = _Jobs.get(i).getAuthenticationPairs();
            IdentifierPair itemp[] = _Jobs.get(i).getIdentifierPairs();
            
            for(int x = 0; x < 5; x++)
            {
                System.out.println(atemp[x].getText());
                System.out.println(atemp[x].getValue());
            }
            for(int x = 0; x < 5; x++)
            {
                System.out.println(itemp[x].getText());
                System.out.println(itemp[x].getValue());
            }
        }
    }
}
